package com.tcxr.validator;

import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import com.tcxr.framework.base.ValidatorBase;
import com.tcxr.vo.LoginView;

@Component
public class LoginViewValidator extends ValidatorBase implements Validator  {
 
	
	
	@Override
	public boolean supports(Class<?> zlass) {
		 
		// 要验证的Model，为假则不验证。  
		return LoginView.class.isAssignableFrom(zlass);
	}

	
	@Override
	public void validate(Object object,Errors errors) {
	 
		LoginView loginView = (LoginView) object;  
		
	        ValidationUtils.rejectIfEmpty(errors, "loUser", "loUser.errors", "用户名的内容不能为空");  
	        ValidationUtils.rejectIfEmpty(errors, "loPassword", "loPassword.errors", "密码的内容不能为空");  
	        
	        if(!validatorLength(loginView.getLoUser(), 16))
	        {
	        	 errors.rejectValue("loUser", "loUser.errors", "用户名不能超过 16 个字符");  
	        }else if(!validatorLength(loginView.getLoPassword(), 16))
	        {
	        	 errors.rejectValue("loPassword", "loPassword.errors", "密码不能超过 16 个字符");  
	        }
	        
	        
	         
	       
	        
	        
	         
	        
	        
	        
//	        errors.rejectValue("loName", "user.name.too_long", "用户名不能超过{20}个字符");  
//	        int length = userVO.getName().length();  
//	        if (length > 20) {  
//	            errors.rejectValue("name", "user.name.too_long", "用户名不能超过{20}个字符");  
//	        }  
//	        length = userVO.getPassword().length();  
//	        if (length < 6) {  
//	            errors.rejectValue("password", "user.password.too_short", "密码太短，不能少于{6}个字符");  
//	        } else if (length > 20) {  
//	            errors.rejectValue("password", "user.password.too_long", "密码太长，不能长于{20}个字符");  
//	        }  
	        
		
	}

}
